package sample.old;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

/**
 * @author Junichiro
 * @description
 * @date 2021-03-21 16:38
 **/

public class EventDemo extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        VBox root = new VBox(30);
        Button button = new Button("点我");
        Label label = new Label("Hello");
        root.getChildren().addAll(label,button);
        root.setAlignment(Pos.CENTER);
        Scene scene = new Scene(root,300,200);
        primaryStage.setScene(scene);
        primaryStage.setTitle("测试");
        primaryStage.show();

        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if (label.getText().equals("Hello")){
                    label.setText("你好");
                }else{
                    label.setText("Hello");
                }
            }
        });
    }
}
